package com.sx.zongzhi.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.sx.zongzhi.R;
import com.sx.zongzhi.adapter.RelationAdapter;
import com.sx.zongzhi.bean.PopulationDetailBean;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by XZY on 2017/11/28.
 * 户籍信息
 */
public class HouseholdInforFragment extends Fragment {

    @BindView(R.id.tv_HomeID)
    TextView tv_HomeID;
    @BindView(R.id.tv_Relation)
    TextView tv_Relation;
    @BindView(R.id.tv_Sex)
    TextView tv_Sex;
    @BindView(R.id.list_View)
    ListView list_View;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_household_infor,container,false);
        ButterKnife.bind(this,view);
        initData();
        return view;
    }

    private void initData() {
        PopulationDetailBean detailBean= (PopulationDetailBean) getArguments().getSerializable("PopulationDetailBean");
        if (detailBean!=null){
            initView(detailBean);
        }
    }

    private void initView(PopulationDetailBean detailBean) {
        tv_HomeID.setText(detailBean.getAccountNumber());
        tv_Relation.setText(detailBean.getRelationShipWithHead()!=null?
        detailBean.getRelationShipWithHead().getDisplayName():"未知");
        tv_Sex.setText(detailBean.getResidentStatus()!=null?
                detailBean.getResidentStatus().getDisplayName():"未知");
        if (detailBean.getInfo()!=null){
            if (detailBean.getInfo().getRows()!=null&&detailBean.getInfo().getRows().size()>0){
                RelationAdapter relationAdapter = new RelationAdapter(getActivity(),
                        R.layout.item_relation_list,detailBean.getInfo().getRows());
                list_View.setAdapter(relationAdapter);
            }
        }
    }
}
